package com.csci;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;

public class Sudoku {

	final int dimension = 9;
	int boxDimension = 3;
	public int[][]puzzleGrid;
	File file;
	int totalClueCounter;
	
	public Sudoku() {
		readInFile();
	}
	
	public Sudoku(int[][] puzzleGrid){
		this.puzzleGrid = puzzleGrid;
	}
	
	public static Sudoku newInstance(Sudoku s){
		if(s == null){
			return null;
		}
		else{
			int[][] tempPuzzleGrid = new int[9][9];
			for(int row = 0; row < 9; row++){
				for(int col = 0; col < 9; col++){
					tempPuzzleGrid[row][col] = s.puzzleGrid[row][col];
				}
			}
			return new Sudoku(tempPuzzleGrid);
		}
		
	}
	
	
	public void readInFile () {
			file = new File("C:\\Users\\grebwerd\\Desktop\\puzzleSolution.txt");
	}

	public void getPuzzle(int puzzleNumber, int percentOfClues, Random rand) {
		try {
			Scanner input = new Scanner(file);
			String puzzle = null;
			for(int i=0; i < puzzleNumber; i++){
				puzzle = input.nextLine();
			}
			System.out.println("puzzle equals " + puzzle);
			convertPuzzle(puzzle, percentOfClues, rand);
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void convertPuzzle(String puzzle, int percentOfClues, Random rand) {
		this.puzzleGrid = new int[9][9];
		int clueCounter = 0;
		int counter = 0;
		for(int i = 0; i < 9; i++){
			for(int j = 0; j < 9; j++){
				if((rand.nextInt(100) < percentOfClues)){
					puzzleGrid[i][j] = Integer.parseInt(puzzle.substring(counter, counter+1));
					clueCounter++;
					totalClueCounter++;
				}
				else{
					puzzleGrid[i][j] = -1;
				}
				counter++;
			}
		}
		System.out.println("The clue counter was " + clueCounter);
	}
}
